import wx

# TODO: pycairo

myEVT_TWO_BUTTON = wx.NewEventType()  # 创建一个事件类型
myEVT_TWO_BUTTON2 = wx.NewEventType()  # 创建一个事件类型


class TwoButtonEvent(wx.PyCommandEvent):  # 定义事件
    def __init__(self, evtType, id):
        super().__init__(evtType, id)
        self.clickCount = 0

    def GetClickCount(self):
        return self.clickCount

    def SetClickCount(self, count):
        self.clickCount = count


EVT_TWO_BUTTON = wx.PyEventBinder((myEVT_TWO_BUTTON, myEVT_TWO_BUTTON2), 2)


class TwoButtonPanel(wx.Panel):

    def __init__(self, parent, id=-1, leftText="Left", rightText="Right"):
        super().__init__(parent, id)
        self.leftButton = wx.Button(self, label=leftText)
        self.rightButton = wx.Button(self, label=rightText, pos=(100, 0))

        self.leftClick = False
        self.rightClick = False
        self.clickCount = 0

        self.leftButton.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
        self.rightButton.Bind(wx.EVT_LEFT_DOWN, self.OnRightClick)

    def OnLeftClick(self, event):
        self.leftClick = True

        evt = TwoButtonEvent(myEVT_TWO_BUTTON2, self.GetId())
        evt.SetClickCount(self.clickCount)  # 事件携带一个点击数
        self.GetEventHandler().ProcessEvent(evt)  # 发送事件

        self.OnClick()
        event.Skip()

    def OnRightClick(self, event):
        self.rightClick = True
        self.OnClick()
        event.Skip()

    def OnClick(self):
        self.clickCount += 1
        if self.leftClick and self.rightClick:  # 触发事件条件
            print("触发事件")
            self.leftClick = False
            self.rightClick = False

            evt = TwoButtonEvent(myEVT_TWO_BUTTON, self.GetId())  # 创建了一个事件
            evt.SetClickCount(self.clickCount)  # 事件携带一个点击数
            self.GetEventHandler().ProcessEvent(evt)  # 发送事件
            # self.ProcessEvent(evt)


class CustomEventFrame(wx.Frame):

    def __init__(self, parent, id):
        super().__init__(parent, id, 'Click Count:0', size=(300, 100))

        panel = TwoButtonPanel(self)

        self.Bind(EVT_TWO_BUTTON, self.OnTwoClick)

    def OnTwoClick(self, event):
        if event.GetEventType() == myEVT_TWO_BUTTON:
            self.SetTitle("Click Count: %s" % event.GetClickCount() + "10")
        else:
            self.SetTitle("Click Count: %s" % event.GetClickCount())


if __name__ == '__main__':
    app = wx.App()

    frame = CustomEventFrame(parent=None, id=-1)
    frame.Show(True)
    app.MainLoop()
